project(ImgReadShow)

find_package(OpenCV REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})  # headers
link_libraries(${OpenCV_LIBS})
#find_package(Python COMPONENTS Interpreter Development)
find_package(pybind11 REQUIRED)

# 匹配文件
file(GLOB_RECURSE FILE_INCLUDE include/*.h)
file(GLOB_RECURSE FILE_SRC src/*.cpp)
file(GLOB_RECURSE FILE_WRAPPER wrapper/*.cpp)

# 把c++文件编译成lib
include_directories(include)

add_library(
        ${PROJECT_NAME} SHARED
        ${FILE_INCLUDE} ${FILE_SRC} ${FILE_WRAPPER}
)

target_link_libraries(
        ${PROJECT_NAME}
            PUBLIC
                pybind11::embed
)

######### 生成方便导入的 xxConfig.cmake ##########

# 1.1 匹配表示头文件源和安装相对位置
target_include_directories(${PROJECT_NAME}
        INTERFACE
        $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
        $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)

# 1.2 指定哪些头文件需要被安装
set_target_properties(${PROJECT_NAME}
        PROPERTIES
            PUBLIC_HEADER ${FILE_INCLUDE}
)

# 1.3 创建模块的target文件，用于描述include,lib的位置
install(
        TARGETS ${PROJECT_NAME}
        EXPORT ${PROJECT_NAME}Targets
        PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
        RUNTIME DESTINATION bin
        LIBRARY DESTINATION lib
        ARCHIVE DESTINATION lib
)

# 1.4 模块target文件安装，并添加模块namespace
install(
        EXPORT ${PROJECT_NAME}Targets
        FILE ${PROJECT_NAME}Targets.cmake
        DESTINATION ${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME}/cmake
        NAMESPACE ${PROJECT_NAME}::
)


# 2.1 使用标准库创建Config文件
configure_package_config_file(
        ${PROJECT_NAME}Config.cmake.in
        ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
        INSTALL_DESTINATION ${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME}/cmake
)
# 2.2 Config安装
install(
        FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
        DESTINATION ${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME}/cmake
)


#####################################

